<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    //获取基准，小于基准的放左边，大于基准的放右边，这样循环
    let arr=[2,3,6,9,2,3,4,5,6]
    function swap (arr,i,j){
      var temp = arr[i]
      arr[i]= arr[j]
      arr[j] =temp
    }
    function quickSort(arr,left,right){
      var len =arr.length,
      p,
      left = typeof left !== 'number' ? 0 : left,
      right = typeof right !== 'number' ? len-1 :right
      if(left< right){
        p = partition(arr,left,right)
        quickSort(arr,left,p-1)
        quickSort(arr,p+1,right)
      }
    }
    function partition(arr,left,right){
      var l = left
      var index = l+1
      for(let i =index;i<=right;i++){
        if(arr[i]<arr[l]){
          swap(arr,i,index)
          index++
        }
      }
      swap(arr,l,index-1)
      return index-1
    }
    console.time('123')
    quickSort(arr)
    console.timeEnd('123')
    console.log(arr)
  </script>
</body>
</html>